using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class Employers_resumeapplied : System.Web.UI.Page
{
    string jobID = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Contents["rcuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        jobID= Request.QueryString.Get("JobID");
        if (!IsPostBack)
            ShowData(jobID);

    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        ShowData(jobID);
        GridView1.PageIndex = e.NewPageIndex;
    }
    void ShowData(string jobID)
    {
        try
        {
            ControlHelper cls = new ControlHelper("");
            cls.CommandText = "SPViewAppliedResumes";
            cls.ParameterCollection = new string [2] {"@RecruiterID", "@JobID" };
            cls.ValueCollection = new string[2] { 
            Convert.ToString(Session.Contents["rcuserid"]), jobID};
            cls.CommandType = CommandType.StoredProcedure;
            cls.InitProperties();
            cls.FillDataTableToGridView(this.GridView1, 10, 10, PagerButtons.NumericFirstLast);
             
        }
        catch(Exception ex)
        {
            Literal1.Text = ex.Message;
        }
    }
    
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        string resumeID = GetIDToAct();
        if (resumeID != "")
        {
             
            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string resume  in resumeID.Split(','))
                sqlServerProvider.DeleteAppliedResume(
                Convert.ToString(Session["rcuserid"]),jobID, resume);
            ShowData(jobID);
        }
    }
     
    
    string GetIDToAct()
    {

        string resumeID = "";
        foreach (GridViewRow gridViewRow in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)
            gridViewRow.FindControl("chkResumeID");
            if (checkBox.Checked)
            {
                try
                {
                    resumeID +=
                    gridViewRow.Cells[1].Text + ",";
                }
                catch (Exception ex)
                {
                    Literal1.Text = ex.Message;
                }
            }

        }
        if (resumeID != "")
        {
            resumeID = resumeID.Substring(0, resumeID.Length - 1);
        }
        return resumeID;
    }
    protected void btnAccept_Click(object sender, EventArgs e)
    {
        string resumeID = GetIDToAct();
        if (resumeID != "")
        {

            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string resume in resumeID.Split(','))
                sqlServerProvider.ChangeStatusOfResume(
                Convert.ToString(Session["rcuserid"]), jobID, resume,"2");
            ShowData(jobID);
        }
    }
    protected void btnReject_Click(object sender, EventArgs e)
    {
        string resumeID = GetIDToAct();
        if (resumeID != "")
        {

            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string resume in resumeID.Split(','))
                sqlServerProvider.ChangeStatusOfResume(
                Convert.ToString(Session["rcuserid"]), jobID, resume, "1");
            ShowData(jobID);
        }
    }
    protected void btnKeep_Click(object sender, EventArgs e)
    {
        string resumeID = GetIDToAct();
        if (resumeID != "")
        {

            SqlServerProvider sqlServerProvider
                        = new SqlServerProvider();
            foreach (string resume in resumeID.Split(','))
                sqlServerProvider.ChangeStatusOfResume(
                Convert.ToString(Session["rcuserid"]), jobID, resume, "3");
            ShowData(jobID);
        }
    }
}
